package com.example.service.impl;

import com.example.mapper.TeacherMapper;
import com.example.pojo.*;
import com.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Teacher login(Teacher teacher) {
        return teacherMapper.login(teacher);
    }

    @Override
    public String getNameByUserName(String username) {
        return teacherMapper.getNameByUserName(username);
    }

    @Override
    public List<Plan> listplan(String username) {
        return teacherMapper.getPlanByUsername(username);
    }

    @Override
    public Teacher getByUserMsg(String username) {
        return teacherMapper.getByUserMsg(username);
    }

    @Override
    public void addPlan(Progress plan) {
        plan.setCreateTime(LocalDateTime.now());
        plan.setUpdateTime(LocalDateTime.now());
        plan.setStatus((short) 0);
        teacherMapper.addPlan(plan);
    }

    @Override
    public Integer getIdByUser(String username) {
        return teacherMapper.getIdByUser(username);
    }

    @Override
    public Plan selectPlan(SelectDeta selectDeta) {
        return teacherMapper.selectPlan(selectDeta);
    }

    @Override
    public Teacher login2(Teacher teacher) {
        return teacherMapper.login2(teacher);
    }

    @Override
    public List<HomeWork> listHomeWork(String username) {
        return teacherMapper.getHomeWork(username);
    }

    @Override
    public void addHomeWork(HomeWork homeWork) {
        homeWork.setCreateTime(LocalDateTime.now());
        homeWork.setUpdateTime(LocalDateTime.now());
        teacherMapper.addHomeWork(homeWork);
    }

    @Override
    public HomeWork selectHomeWork(SelectDeta selectDeta) {
        return teacherMapper.selectHomeWork(selectDeta);
    }

    @Override
    public List<Task> listTask(String username) {
        return teacherMapper.getTask(username);
    }

    @Override
    public Task selectTask(SelectDeta selectDeta) {
        return teacherMapper.selectTask(selectDeta);

    }

    @Override
    public void addTask(Task task) {
        task.setCreateTime(LocalDateTime.now());
        task.setUpdateTime(LocalDateTime.now());
        teacherMapper.addTask(task);
    }

    @Override
    public Select getByUserName(String username) {
        String name = teacherMapper.getName(username);
        List<StudentHomeWork> list = teacherMapper.getByhw(username);
        Select select = new Select(name, list);
        return select;
    }

    @Override
    public List<Announcemen> getAnnoun(String username) {
        Integer greadClassId = teacherMapper.greadClassId(username);
        List<Announcemen> announcemenList = teacherMapper.getAnnoun(greadClassId);
        return announcemenList;
    }

    @Override
    public List<Progress> listProgress(String username) {
        return teacherMapper.listProgress(username);
    }

    @Override
    public void addProgress(Progress progress) {
        progress.setCreateTime(LocalDateTime.now());
        progress.setUpdateTime(LocalDateTime.now());
        progress.setStatus((short) 0);
        teacherMapper.addProgress(progress);
    }

    @Override
    public void setPassWord(Pass pass) {
        teacherMapper.setPassWord(pass);
    }

    @Override
    public List<Opinion> listOpinion(String username) {
        List<Opinion> opinionList = teacherMapper.listOpinion(username);
        return opinionList;
    }

    @Override
    public List<Teacher> listTeacher() {
        List<Teacher> teacherList = teacherMapper.listTeacher();
        return teacherList;
    }

    @Override
    public List<Student> listStudent(String username) {
        List<Student> studentList = teacherMapper.listStudent(username);
        return studentList;
    }

    @Override
    public void addClassFee(ClassFee classFee) {
        classFee.setBalance(classFee.getBalance() + classFee.getAdd() - classFee.getReduce());
        Integer id = teacherMapper.getId(classFee.getUsername());
        classFee.setOperatorId(id);
        classFee.setCreateTime(LocalDateTime.now());
        classFee.setUpdateTime(LocalDateTime.now());
        teacherMapper.addClassFee(classFee);
    }

    @Override
    public List<Teacher> getTeacherByClass(String username) {
        List<Teacher> teacherList = teacherMapper.getTeacherByClass(username);
        return teacherList;
    }

}
